package cn.kgc.controller;
import cn.kgc.pojo.Revenue;

import cn.kgc.service.RevenueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author 谢里夫老师
 * @version 1.0
 * @date 2022/10/15 - 9:41
 */


@Controller
public class RevenueController {


    @Autowired
    private RevenueService revenueService;

    @RequestMapping("/seleRevenueByNum")
    @ResponseBody
    public Map<String, Object> seleRevenueByNum(
            String page,
            String limit,
            String orderNum) {

        HashMap<String, Object> map = new HashMap<>();

        int crrPage = 1;
        if (page != null && !"".equals(page)) {
            crrPage = Integer.parseInt(page);
        }
        int lim = Integer.parseInt(limit);
        crrPage = (crrPage - 1) * lim;

        List<Revenue> revenues = revenueService.seleRevenueByNum(crrPage, lim, orderNum);
        //得到总页数
        int totalPage = revenueService.getTotalCount(orderNum);
        map.put("count", totalPage);
        map.put("data", revenues);
        map.put("code", 0);
        map.put("msg", "");

        return map;
    }



    //收入报表
    @RequestMapping("/srBaoBiao")
    @ResponseBody
    public Map<String,Object> srBaoBiao(){
        HashMap<String, Object> map = new HashMap<>();

        List<HashMap<Integer, String>> maps = revenueService.srBaoBiao();
        System.out.println(maps);
        map.put("maps",maps);
        map.put("code",0);
        map.put("msg","成功获取到图表");

        return map;
    }





    /*//新增房间
    @RequestMapping("/addRevenue")
    @ResponseBody
    public String addRevenue(Revenue revenue) {

        revenueService.addRevenue(revenue);
        return "redirect:/seleRevenueByNum";
    }*/
}
